<template>
  <div class="container">
    <Navbar title="我的订单"></Navbar>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="已经到底了"
      @load="onLoad"
    >
      <div class="order">
        <div class="order-item" v-for="item in orderList.list" :key="item.id">
          <div class="title">
            <div class="date">{{item.created_at | formatTime}}</div>
            <div class="status">{{item.status_text}}</div>
          </div>
          <div class="body">
            <div class="role">{{item.goods[0].goods_name}}</div>
            <div class="charge"><span>￥</span>{{item.goods[0].charge}}</div>
          </div>
          <div class="payment">{{item.payment_text}}</div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import Navbar from '@/components/common/Navbar';
import { getOrderList } from '@/network/member';

export default {
  components: {
    Navbar,
  },
  data() {
    return {
      loading: false,
      finished: false,
      orderList: { page: 1, list: [] },
    };
  },
  methods: {
    onLoad() {
      getOrderList(this.orderList.page).then((res) => {
        this.orderList.list.push(...res.data.data);
        this.loading = false;
        this.orderList.page += 1;
        if (this.orderList.page >= res.data.last_page) {
          this.finished = true;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  height: 100vh;
  background-color: #f6f6f6;
  .order-item {
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    height: 86px;
    padding: 0 12px;
    background-color: #fff;
    border-top: 1px solid rgba(0, 0, 0, .06);
    .title,
    .body {
      display: flex;
      justify-content: space-between;
    }
    .title,
    .payment {
      color: #999;
      font-size: 12px;
    }
    .body {
      .role {
        font-size: 15.2px;
      }
      .charge {
        font-size: 20px;
        span {
          font-size: 12px;
        }
      }
    }
  }
}
</style>
